package com.sunnypower.rushfitapp.BodyDataPart;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.sunnypower.rushfitapp.R;
import com.sunnypower.rushfitapp.db.BodyData;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class BodyDataAdapter extends ArrayAdapter<BodyData> {

    public BodyDataAdapter(@NonNull Context context, int textViewResourceId, @NonNull List<BodyData> objects) {
        super(context, textViewResourceId, objects);
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        BodyData bodyData = getItem(position);
        View view = LayoutInflater.from(getContext()).inflate(R.layout.body_data_part, parent, false);
        TextView p_update_date = view.findViewById(R.id.p_update_date);
        TextView p_weight = view.findViewById(R.id.p_weight);
        TextView p_fatRate = view.findViewById(R.id.p_fatRate);
        TextView p_waist = view.findViewById(R.id.p_waist);
        TextView p_hipline = view.findViewById(R.id.p_hipline);
        TextView p_chest = view.findViewById(R.id.p_chest);
        TextView p_thigh = view.findViewById(R.id.p_thigh);

        p_update_date.setText(bodyData.getTime());
        p_weight.setText(" " + bodyData.getHeight());
        p_weight.setText(" " + bodyData.getWeight().toString());
        p_fatRate.setText(" " + bodyData.getFatRate().toString().substring(2, 4) + "%");
        p_waist.setText(" " + bodyData.getWaist().toString());
        p_hipline.setText(" " + bodyData.getHipline().toString());
        p_chest.setText(" " + bodyData.getChest().toString());
        p_thigh.setText(" " + bodyData.getThigh().toString());
        return view;
    }
}
